<?php

jimport('joomla.application.component.controller');

class KontaktController extends JController
{
    /**
     * Method to display the view
     *
     * @access    public
     */
    function display()
    {
        //parent::display();
		
		$vLayout = JRequest::getCmd( 'layout', 'default' );
		$vName = JRequest::getCmd( 'view', 'index' );
		$mName = JRequest::getCmd( 'model', 'kontakt' );
		
		$document = &JFactory::getDocument();
		$vType = $document->getType();

		// Get/Create the view
		$view = &$this->getView( $vName, $vType);

		// Get/Create the model
		if ($mName && $model = &$this->getModel($mName)) {
			// Push the model into the view (as default)
			$view->setModel($model, true);
		}
		
		// message		
		/*global $mainframe, $option;
		$msg = $mainframe->getUserState( $option.'msg' );
		$mainframe->setUserState( $option.'msg', '' );
		$view->assignRef( 'msg', $msg );*/

		// Set the layout
		$view->setLayout($vLayout);

		// Display the view
		$view->display();
    }
	
	function submit()
	{
//		jimport('mylibs.globalModel');
//		$globalModel = new globalModel();
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
		
				
		$post	= JRequest::get('post');
		
//		$name		= JRequest::getVar( 'name',			'',			'post' );
		$email		= JRequest::getVar( 'email',		'',			'post' );		
		$subject	= JRequest::getVar( 'subject',		'',			'post' );
		$message_p    = JRequest::getVar( 'message',		'',			'post' );
		
		
		
		//-- begin insert into acajoom
//		include_once 'administrator/components/com_acajoom/classes/class.subscribers.php';
//		include_once 'administrator/components/com_acajoom/classes/class.erro.php';
//		include_once 'administrator/components/com_acajoom/classes/class.acajoom.php';
//		$subscribers = new subscribers();
//		$subscribers->insertOneSubscriber();
		//-- end insert into acajoom

		jimport('joomla.mail.helper');
		$mail = JFactory::getMailer();
		
//		$data_2 = $globalModel->getAllArticle(); 
//
//		if ( !empty($message_post) ){
//			$message = "<center>";
//			$message .= $message_post."</center><br/><br/><br/>";
//		}
//		
//		$message .= "
//		<html xmlns='http://www.w3.org/1999/xhtml'>
//<head>
//<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
//<title>Alsace | Bringer menuen i balance | Newsletter Vol. 01 - May 2011</title>
//</head>
//
//<body style='background-color: #e0eff6;'>
//    <table width='650' align='center' cellpadding='0' cellspacing='0' border='0' style=' background-color: #fff; margin: 10px auto; font-family: Helvetica, Arial, sans-serif; font-size: 12px; background:#000;'>
//        <tbody>
//        	<tr style='background-color: #e0eff6;'><td colspan='2' style='padding-bottom: 5px;'><a href='http://www.vinsalsace.com/da/Nyheder' style='color: #000; text-decoration: none;'>Se Alsaces nyhedsbrev i din browser</a></td></tr>
//            <tr valign='top'>
//                <td align='left' valign='top' width='250' height='120' style='padding: 21px 0 0 21px;'>
//                    <img border='1' src='".JURI::root()."templates/rhuk_milkyway/img/page_heading.png' alt='NYHEDER OM VINENE FRA  ALSACE' />
//                </td>
//                <td valign='top' align='right' width='300' height='120' style='padding: 8px 21px 0 0; background-color:#000;'>
//                    <a href='http://www.alsacevin.net' title='Alsace -  Bringer menuen i balance'><img border='0' src='".JURI::root()."templates/rhuk_milkyway/img/alsace_logo.png' alt='Alsace -  Bringer menuen i balance' /></a>
//                </td>
//            </tr>
//            <tr style='background:#fff;'>
//                <td width='426' valign='top' style='padding: 25px 0 0 15px;'>
//                    <table width='410' align='center' cellpadding='0' cellspacing='0' border='0' style='font-family: Helvetica, Arial, sans-serif; font-size: 12px;'>
//                        <tbody>
//                            <tr>
//                            	<td><h1 style='font-size: 18px; font-weight: normal; border-bottom: 1px solid #000; padding-bottom: 5px; letter-spacing: -1px;'>".strtoupper(date("M Y",strtotime($data_2[0]['created'])))."</h1></td>
//                            </tr>";				
//		$message .="
//                            <tr>
//                            
//                                <td align='center' valign='top' style='padding: 10px 0 20px 0; border-bottom: 1px solid #000;'>
//                                	<img src='".JURI::root().$data_2[0]['article_image']."' alt='' />
//                                    <h1 style='font-size: 25px; font-weight: normal; margin-bottom: 0; text-align: left; letter-spacing: -1.5px;'>".$data_2[0]['title']."</h1>
//                                    <p style='font-size: 12px; text-align: left; margin-top: 5px;'>
//                                    	".$globalModel->getShortText($data_2[0]['introtext'],279)."
//                                        <br/>
//                                        <a style='color: #000;' href='".JURI::root()."index.php?option=com_content&view=article&id=".$data_2[0]['id']."'>Læs mere</a>
//                                    </p>
//                                </td>
//                            </tr>
//                            <tr>
//                            
//                                <td align='center' valign='top' style='padding: 10px 0 20px 0;'>
//                                	<img src='".JURI::root().$data_2[1]['article_image']."' alt='' />
//                                    <h1 style='font-size: 25px; font-weight: normal; margin-bottom: 0; text-align: left; letter-spacing: -1.5px;'>".$data_2[1]['title']."</h1>
//                                    <p style='font-size: 12px; text-align: left; margin-top: 5px;'>
//                                    	".$globalModel->getShortText($data_2[1]['introtext'],279)."
//                                        <br/>
//                                        <a style='color: #000;' href='".JURI::root()."index.php?option=com_content&view=article&id=".$data_2[1]['id']."'>Læs mere</a>
//                                    </p>
//                                </td>
//                            </tr>
//                           
//                        </tbody>
//                    </table>
//                </td>
//                <td valign='top' style='padding: 25px 15px 0 0;'>
//                	<table align='right' width='186' cellpadding='0' cellspacing='0' border='0' style='font-size: 12px; font-family: Helvetica, Arial, sans-serif;'>
//                    	<tbody>
//                        	<tr>
//                            	<td>
//                                	<h2 style='font-size: 15px; font-weight: normal; line-height: 20px; padding-bottom: 5px;  border-bottom: 1px solid #000;'>Flere nyheder</h2>
//                                    <ul style='list-style: disc;'>";
//										
//                                    		$data = $globalModel->getAllArticle();   
//                                    		foreach ( $data as $key=>$value ){                                 		
//                                    	
//                            $message .= "<li style=' margin: 15px 0 15px -24px; padding: 0;'>
//                                            <a href='".JURI::root()."index.php?option=com_content&view=article&id=".$value['id']."' style='text-decoration: none; color: #000;'>
//                                            	<span style='font-size: 14px; color: #888; margin-bottom: 3px; letter-spacing: -0.75px;'>".$value['title']."</span>
//                                                <br/>
//                                                <span>".$globalModel->getShortText($value['introtext'],113)."</span>
//                                            </a>
//                                        </li>";
//                                    		}
//                      $message .= "</ul>
//                                </td>
//                            </tr>
//                            <tr>
//                            	<td>
//                                	<h2 style='font-size: 15px; font-weight: normal; line-height: 20px; padding-bottom: 5px; margin: 0px;  border-bottom: 1px solid #000; letter-spacing: -0.75px;'>Send til en ven</h2>
//                                    <p style='margin-top: 5px;'>Kender du nogen der er interreseret i vin? Så send denne videre. <a href='".JURI::root()."index.php?option=com_kontakt'>Klik her</a></p>
//                                </td>
//                            </tr>
//                            <tr>
//                            	<td style='padding-top:20px;'>
//                                	<a href='http://www.franceagrimer.fr' title='France AgrilMer'><img border='0' src='".JURI::root()."templates/rhuk_milkyway/img/franceagrilmer.jpg' alt='France AgrilMer' /></a>
//                                    <a href='http://www.ambafrance-dk.org/' title='Frankrig i Danmark'><img border='0' src='".JURI::root()."templates/rhuk_milkyway/img/france_embassy.jpg' alt='Frankrig i Danmark' /></a>
//                                </td>
//                            </tr>
//                            <tr>
//                            	<td align='center' style='padding-top:30px;'>
//                                	<img src='".JURI::root()."templates/rhuk_milkyway/img/img_02.jpg' alt='' />
//                                </td>
//                            </tr>
//                        </tbody>
//                    </table>
//                </td>
//            </tr>
//            <tr height='60'>
//                <td style='padding: 30px 25px 15px 12px;'>
//                    <p style='color: #fff;'>Nyhedsbrevet udgives af: Sopexa, Højbro Plads 15, 2. 1200 København K, Danmark. Yderligere information kan findes på <a style='color:#fff; text-decoration: none;' href='http://www.alsacevin.net'>www.alsacevin.net</a>.</p>
//                </td>
//                <td style='padding: 30px 10px 15px 0;'>
//                    <p style='color: #fff;'>Afmeld nyhedsbrev<br/><a target='_blank' href='mailto:peter-esper.larsen@sopexa.com?subject=Afmeld nyhedsbrev&body=Venligst frameld mig fra jeres nyhedsbrev.' style='color:#fff; text-decoration: none; font-size: 10px;'>Klik her for at afmelde Alsace nyhedsbrev</a></p>
//                </td>
//            </tr>
//        </tbody>
//    </table>
//</body>
//</html>		
//		";
//		
//		$config = JFactory::getConfig()->toArray();
//		
//		if ( empty($subject) ){
//			$subject = 'Emailing: Alsace  Bringer menuen i balance  Newsletter Vol. '.strtoupper(date("M Y",strtotime($data_2[0]['created'])));
//		}
		
		$message = "<a href='http://www.alsacenyhed.dk'>www.alsacenyhed.dk</a>";
		if ( !empty($message_p) ){
			$strFind = 'www.alsacenyhedsbrev.dk';
			$strReplace = $message;
			$content = str_replace($strFind, $strReplace, $message_p);
			$message = $content;
		}
		
		$mail->addRecipient( $email );
//		$mail->setSender( array( $email, $name ) );
		$mail->IsHTML(true);
		$mail->setSender( $config['mailfrom'] );
		$mail->setSubject( $subject );
		$mail->setBody( nl2br($message) );

		$sent = $mail->Send();
		
		// message
		$msg = '';//JText::_( 'Submit' );
		
		$link = 'index.php?option=com_kontakt&view=index&layout=response';//JRoute::_('index.php?option=com_kontakt&view=index&layout=response&Itemid=6');
		$this->setRedirect($link, $msg);
	}
}
?> 